package com.cyy.api.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.cyy.common.domain.Response;
import com.cyy.common.pojo.req.CommentAddReq;
import com.cyy.common.service.CommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author caoyunyou
 */
@Tag(name = "评论-API", description = "文章-API")
@RestController
@RequestMapping("/v1/comments")
@RequiredArgsConstructor
public class ApiCommentController {

    private final CommentService commentService;

    @Operation(summary = "树形展示评论信息")
    @GetMapping("/comment/{id}")
    public Response treeByArticleComment(@PathVariable(name = "id") Long id) {
        return Response.success().data(commentService.treeByType("COMMENT", id));
    }

    @Operation(summary = "添加评论")
    @PostMapping("/comment")
    public Response addComment(@RequestBody @Validated CommentAddReq req) {
        commentService.addComment(req);
        return Response.success();
    }

    @Operation(summary = "友链页面留言列表")
    @GetMapping("/link")
    public Response treeLinkComment() {
        return Response.success().data(commentService.treeByType("LINK", null));
    }

    @Operation(summary = "分页展示留言板评论列表")
    @GetMapping("/message/page")
    public Response pageMessage(@RequestParam("startIndex") Integer startIndex) {
        return Response.success().data(commentService.queryMessagePage(startIndex));
    }

    @Operation(summary = "评论点赞")
    @PostMapping("/clickLike/{id}")
    @SaCheckLogin
    public Response clickLike(@PathVariable("id") Integer id) {
        commentService.clickLike(id);
        return Response.success();
    }

    @Operation(summary = "评论踩")
    @PostMapping("/clickDislike/{id}")
    @SaCheckLogin
    public Response clickDislike(@PathVariable("id") Integer id) {
        commentService.clickDislike(id);
        return Response.success();
    }
}
